//
//  BHCommonReportTextCell.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/7/15.
//

import UIKit

class BHCommonReportTextCell: UICollectionViewCell {

    @IBOutlet weak var text_view: UITextView!
    @IBOutlet weak var place_label: UILabel!
    
    var textViewDidEndEditingBlock:((String) -> Void)?
    
    var contentText: String = "" {
        didSet {
            self.place_label.isHidden = contentText.isEmpty != true
            self.text_view.text = contentText
        }
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        self.text_view.delegate = self

        self.place_label.addViewAction {[weak self] (_) in
            self?.text_view.becomeFirstResponder()
        }
    }

}
extension BHCommonReportTextCell: UITextViewDelegate {
    func textViewDidChange(_ textView: UITextView) {
        self.place_label.isHidden = !textView.text.isEmpty
    }
    
    func textViewDidEndEditing(_ textView: UITextView) {
        self.textViewDidEndEditingBlock?(textView.text ?? "")
    }
}
